
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Author:  LJ
Email:   admin@attacker.club
Time:    2020/3/26 16:31
Description: 将jumpserver资产导入saltstack
"""
import csv
import re


pwd = input("当前环境ROOT通用密码:\t")
with open('asset_2020-03-26_16-27-43.csv', 'r') as myForm:
    lines = csv.reader(myForm)
    # print(lines)

    with open('roster', 'w') as f:

        try:
            for line in lines:
                if "True" in line:
                    print(line)
                    port = re.findall(r'\d+', line[3])[0]
                    f.write(
                        "%s:\n\thost:%s\n\tuser:%s\n\tpasswd:%s\n\tport:%s\n" % (
                        line[2], line[1], "root", pwd, port))
                    f.flush()


        except Exception as e:
            print(e)

